﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Data;

namespace Extractor.LibCode
{ public struct File_Attribute
        {
            public string flpath;
            public string filename;
            public string extension;
            public string filesize;
            public string fldimension;
            public string flWidth;
            public string flHeight;
            public string dtcreated;
            public string dtmodified;
            public string BROKEN;
        }
    public class cFileManagement:cDBService
    {
        public cFileManagement()
        {
        }

        public void deletefile()
        {
            string ss = @"select flpath+'\'+filename as spath,* from  tbfilebkp where 1=1 and filesize= 5034";
            DataTable dt= new DataTable();
            dt = Dbserver.ExecuteQuery(ss, "");
            foreach (DataRow dr in dt.Rows)
            {
                string spath = dr["spath"].ToString();
                if (File.Exists(spath))
                {
                    try
                    {
                        File.Delete(spath);
                    }
                    catch
                    {
                    }

                }
            }
        }
        public bool catetfiletodb(File_Attribute fa)
        {
            DataTable dt = new DataTable();
            dt = getTableStructure("TBFILEBKP");
            string fileid = new cDBHelper().genIDCommit("FILEID");          
            
            DataRow dr = dt.NewRow();
            dr["FILEID"] = fileid;
            dr["DTCREATED"] = fa.dtcreated;
            dr["DTMODIFIED"] = fa.dtmodified;
            dr["EXTENSION"] = fa.extension;
            dr["FILENAME"] = fa.filename;
            dr["FILESIZE"] = fa.filesize;
            dr["FLDIMENSION"] = fa.fldimension;
            dr["FLHEIGHT"] = fa.flHeight;
            dr["FLPATH"] = fa.flpath;
            dr["FLWIDTH"] = fa.flWidth;
            if (fa.BROKEN != null)
                dr["BROKEN"] = fa.BROKEN;

            dt.Rows.Add(dr);
            string s="";
            return ExecuteUpdate(dt, out s);




        }
    }
}
